package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.SaleList;
import com.atguigu.jxc.service.SaleListGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author fenge
 */
@RequestMapping("saleListGoods")
@Controller
public class SaleListGoodsController {

    @Autowired
    private SaleListGoodsService saleListGoodsService;

    @PostMapping("save")
    @ResponseBody
    public ServiceVO save(SaleList saleList, String saleListGoodsStr, HttpSession httpSession){

        saleListGoodsService.save(saleList,saleListGoodsStr,httpSession);
        return new ServiceVO(100,"请求成功");
    }

    @PostMapping("list")
    @ResponseBody
    public Map<String,Object> list(String saleNumber, Integer customerId, Integer state, String sTime,String eTime){
        return saleListGoodsService.list(saleNumber,customerId,state,sTime,eTime);
    }

    @PostMapping("goodsList")
    @ResponseBody
    public Map<String,Object> goodsList(Integer saleListId){
        return saleListGoodsService.goodsList(saleListId);
    }

    @PostMapping("delete")
    @ResponseBody
    public ServiceVO delete(Integer saleListId){
        saleListGoodsService.delete(saleListId);
        return new ServiceVO(100,"请求成功");
    }

    @PostMapping("updateState")
    @ResponseBody
    public ServiceVO updateState(Integer saleListId){
        saleListGoodsService.updateState(saleListId);
        return new ServiceVO(100,"请求成功");
    }

    @PostMapping("count")
    @ResponseBody
    public String count(String sTime, String eTime ,Integer goodsTypeId, String codeOrName){
        return saleListGoodsService.count(sTime,eTime,goodsTypeId,codeOrName);
    }

    @PostMapping("getSaleDataByDay")
    @ResponseBody
    public String getSaleDataByDay(String sTime, String eTime){
        return saleListGoodsService.getSaleDataByDay(sTime,eTime);
    }
}
